#ifndef __ISERVICE_REGISTRY_IMPL_H__
#define __ISERVICE_REGISTRY_IMPL_H__

#include "../common/include/registry_ifaces.h"
#include "../common/include/cls_ids.h"
#include "../../include/co_class_base.h"

#include <list>
#include <string>
#include <memory>

namespace Boss
{

  class IServiceRegistryImpl
    : public CoClassBase
        <
          TL::TypeListAdapter
            <
              IServiceRegistry,
              IServiceRegistryCtrl
            >
        >
  {
  public:
    BOSS_DECLARE_STR_CLSID(BOSS_CLSID_ISERVICEREGISTRYIMPL)

    // IServiceRegistry
    virtual TResult BOSS_CALL_TYPE GetModuleIdByCLSID(TGuid classId, IVariant **moduleId) const;
    virtual TResult BOSS_CALL_TYPE GetModuleCoClasses(TGuid moduleId, IEnum **coClassIds) const;
    virtual TResult BOSS_CALL_TYPE GetModulePath(TGuid moduleId, IVariant **path) const;
    virtual TResult BOSS_CALL_TYPE EnumAllModules(IEnum **modules) const;

    // IServiceRegistryCtrl
    virtual TResult BOSS_CALL_TYPE Init(IVariant *path);
    virtual TResult BOSS_CALL_TYPE RegModule(IVariant *path);
    virtual TResult BOSS_CALL_TYPE UnRegModule(IVariant *path);

  private:
    struct ModuleInfo
    {
      typedef std::list<std::string> StringList;
      std::string Id;
      std::string Name;
      std::string Path;
      StringList CoClassesIds;
    };
    typedef std::list<ModuleInfo> ModuleInfoPool;
    typedef std::auto_ptr<ModuleInfoPool> ModuleInfoPoolPtr;
    ModuleInfoPoolPtr Modules;
    std::string FileName;

    static const char EqTag[];
    static const char TabTag[];
    static const char ModuleTag[];
    static const char ModuleNameTag[];
    static const char ModulePathTag[];
    static const char CoClassesTag[];
    static const char CoClassTag[];
    static const char EndCoClassesTag[];
    static const char EndModuleTag[];

    ModuleInfoPoolPtr LoadRegistry() const;
    void SaveRegistry(const ModuleInfoPool &modules) const;
  };

}

#endif  // !__ISERVICE_REGISTRY_IMPL_H__
